feat: libra add reset subcommand.#1261
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements the libra reset subcommand, adding the ability to reset the current HEAD to a specified state with three different modes (soft, mixed, hard). This is part of issue #1239 and provides Git-compatible reset functionality.
- Implements three reset modes: soft (HEAD only), mixed (HEAD + index), and hard (HEAD + index + working directory)
- Adds comprehensive test coverage for all reset modes and edge cases
- Integrates reset command into the CLI interface with proper argument parsing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| libra/src/command/reset.rs | Core implementation of reset functionality with all three modes |
| libra/tests/command/reset_test.rs | Comprehensive test suite covering soft, mixed, hard reset scenarios |
| libra/src/command/mod.rs | Module declaration for reset command |
| libra/src/cli.rs | CLI integration and command parsing for reset |
| libra/tests/command/mod.rs | Test module declaration |
| // Add file to index - but don't modify working directory files | ||
| // Use the blob hash from the tree, not from working directory | ||
| // Get blob size for IndexEntry | ||
| let blob = mercury::internal::object::blob::Blob::load(&item.id); |
There was a problem hiding this comment.
The load method call doesn't handle potential errors. This could panic if the blob object doesn't exist or is corrupted. Use load_object function instead which returns a Result that can be properly handled.
| let blob = mercury::internal::object::blob::Blob::load(&item.id); | |
| let blob = load_object(&item.id) | |
| .map_err(|e| format!("failed to load blob: {e}"))?; |
| assert!(staged.is_empty(), "Index should be reset in mixed reset"); | ||
|
|
||
| // Verify unstaged changes exist (2.txt, 3.txt, 4.txt should be untracked/modified) | ||
| let unstaged = changes_to_be_staged(); |
There was a problem hiding this comment.
The function name changes_to_be_staged() suggests it returns staged changes, but it's being used to check for unstaged changes. This appears to be a semantic mismatch that could lead to incorrect test behavior.
| let unstaged = changes_to_be_staged(); | |
| let unstaged = unstaged_changes(); |
| assert!(staged.is_empty(), "Index should be reset in hard reset"); | ||
|
|
||
| // Verify only untracked files remain | ||
| let unstaged = changes_to_be_staged(); |
There was a problem hiding this comment.
Same issue as above - changes_to_be_staged() function name suggests staged changes but is being used to verify unstaged changes after hard reset.
| let unstaged = changes_to_be_staged(); | |
| let unstaged = unstaged_changes(); |
| assert!(fs::metadata("4.txt").is_ok()); | ||
|
|
||
| // Verify index was reset (4.txt should be untracked) | ||
| let unstaged = changes_to_be_staged(); |
There was a problem hiding this comment.
Consistent with previous issues - the function name and usage don't align semantically, which could lead to test failures or incorrect assertions.
| let unstaged = changes_to_be_staged(); | |
| let unstaged = unstaged_changes(); |
|
@yyjeqhc , 请在 https://github.com/web3infra-foundation/mega/tree/main/aria/contents/docs/libra/command 这里参照其它命令,添加 |
8ebd759 to
644f33f
Compare
Part of #1239
实现libra reset子命令的基本功能。
hard reset
mixed reset
soft reset
综上,3种reset以后工作区/暂存区文件列表和文件内容,表现和git一致。